const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
    entry: {
        entry: './src/index.js'
    },
    output: {
        path: __dirname,
        filename: './release/bundle.js' // release 会自动创建
    },
    module: {
        rules: [{
                test: /\.js?$/,
                exclude: /(node_modules)/,
                use: [{
                    loader: 'babel-loader'
                }]
            }, {
                test: /\.css$/,
                use: [{
                        loader: "style-loader",
                        options: {
                            singleton: true // 处理为单个style标签
                        }
                    },
                    {
                        loader: "css-loader",
                        options: {
                            minimize: true // css代码压缩
                        }
                    }
                ]
            },
            {
                test: /\.(png|jpg|jpeg|gif)$/,
                use: [{
                    loader: "url-loader",
                    // options: {
                    //     name: "[name]-[hash:5].min.[ext]",
                    //     limit: 20000, // size <= 20KB
                    //     publicPath: "static/",
                    //     outputPath: "static/"
                    // }
                }]
            },
            {
                test: /\.html$/,
                use: {
                    loader: 'html-loader'
                }
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './index.html' // bundle.js 会自动注入
        })
    ],
    devServer: {
        contentBase: path.join(__dirname, "./release"), // 根目录
        open: true, // 自动打开浏览器
        port: 9000, // 端口
        proxy: {
            '/api/*': {
                target: 'http://localhost:8880'
            }
        }
    },
}